<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("basePath", basePath);
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主题管理</title>
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet"
	href="${basePath }/admin/bower_components/bootstrap/dist/css/bootstrap.min.css">

</head>
<body>

	<table class="table table-hover">
		<thead>
			<a href="${basePath }admin/toEditSpecial.action" ><span
				class="btn btn-primary btn-lg active">添加主题</span></a>
			<tr>
				<th>编号</th>
				<th>名称</th>
				<th>电视剧</th>
				<th>状态</th>
				<th>&nbsp;&nbsp;操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${specialList }" var="special">
				<tr>
					<th scope="row">${special.id }</th>
					<td>${special.name }</td>
					<td id="tvs">${special.tvids }</td>
					<td>${special.status }</td>
					<td><a
						href="${basePath }admin/toEditSpecial.action?id=${special.id}"><span
							class="glyphicon glyphicon-pencil"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="${basePath }admin/deleteSpecial.action?id=${special.id}"
						onclick="return confirm('是否确认删除数据？')"><span
							class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="javascript:;" onclick="enableModel(${special.id })"><span
							></span>添加TV</a></td>
				</tr>
			</c:forEach>
		</tbody>

	</table>
	<table class="table table-hover" style="position: fixed; top: 400px;">
		<thead>

			<tr>
				<td colspan="7"></td>

			</tr>

			<th width="50">编号 </th>
				<th width="250">电视剧名称</th>
				<th width="550">内容</th>
				<th>图片</th>
				<th width="100">链接地址</th>
		</thead>
		<tbody>
			<c:forEach items="${tvList }" var="tv">
				<tr>
					<th scope="row">${tv.id }</th>
					<td>${tv.name }</td>
					<td>${tv.content }</td>
					<td>${tv.image }</td>
					<td>${tv.url }</td>
					
				</tr>
			</c:forEach>

		</tbody>

	</table>

	<div class="modal fade" tabindex="-1" role="dialog"
		aria-labelledby="gridSystemModalLabel" id="TVmodel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">

				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="gridSystemModalLabel">添加数据</h4>
				</div>
				<div class="modal-body">
					
					<label for="InputTvs" class="col-sm-2 control-label">电视剧</label> <label
						class="checkbox-inline"> <c:forEach items="${tvList }"
							var="tvs">
							<div class="checkbox">
								<label> <input name="tvids" type="checkbox"
									value="${tvs.id }"> ${tvs.name }
								</label>
							</div>

						</c:forEach>

						<div class="modal-footer">
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
							<a href="javascript:;" class="btn btn-primary"
								onclick="updateTVIDS()" id="addTVids">添加</a>
						</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
	</div>
	
	<!-- Bootstrap core JavaScript
================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script
		src="https://cdn.bootcdn.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
	<script
		src="https://cdn.bootcdn.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
	<script type="text/javascript">
	
	
	
	
		function enableModel(id) {
			
			//$("p").prependTo("#tvs");
			

			$('#TVmodel').modal()
			
			
			$("#addTVids").attr("specil_id",id);
			
			/*
			更新TVIDS
			1、主题的编号 ，传值过来
			2、选择的TV的编号
			
			*/

		}
		//更新主题的电视剧
		function updateTVIDS(){
		var tvs=$("input[name='tvids']")
		var tvids="";//获得所有选中的电视剧的id值，要拼接成'1,2,3'的字符串
	    
		for(i=0;i<tvs.length;i++){
			if(tvs[i].checked == true){
				tvids+=tvs[i].value+",";
			}			
		}
		if(tvids.substr(tvids.length-1)== ','){
			 tvids = tvids.substr(0,tvids.length-1);
		 }
	
		
		
			//通过ajax请求
			var id=$("#addTVids").attr("specil_id");
			$.ajax({
				   type: "POST",
				   url: "${basePath }admin/updateTvids.action",
				   data: "id="+id+"&tvids="+tvids,
				   success: function(msg){
				     alert( "Data Saved: " + msg );
				     $('#TVmodel').modal('hide');
				     window.location.reload();
				     //getTVS(tvids);
				   }
				  
				});
			
	
		}
		//获取选中电视剧的信息
		function getTVS(tvids){
			
			
			$.ajax({
				   type: "POST",
				   url: "${basePath }admin/api/specil/tvids",
				   data: "tvids="+tvids,
				   success: function(msg){
					   
					   
					   
				    
				   }
				});
			
			
		}
	</script>
</body>
</html>